package com.pennphoto.client;

import java.util.ArrayList;
import java.util.HashMap;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Tree;
import com.google.gwt.user.client.ui.TreeItem;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.pennphoto.client.Circles.*;
public class CirclesPanel {
	private int userid;
	
	public CirclesPanel(int uid){
		userid = uid;
	}
	
	public VerticalPanel loadCircle() throws Exception{
		final VerticalPanel vp = new VerticalPanel();
		Label circle = new Label("Circles");
		vp.add(circle);
		
		try{
			final QueryServiceAsync engine = GWT.create(QueryService.class);
			engine.getCircles(userid, new AsyncCallback<Circles> (){
				public void onFailure(Throwable caught) {
					// Show the RPC error message to the user
					caught.printStackTrace();
				}

				public void onSuccess(Circles result) {
						HashMap<String,HashMap<Integer,String>> hm = new HashMap<String,HashMap<Integer,String>>();
						HorizontalPanel vp1 = new HorizontalPanel();
						hm=result.getFriends();
						for(String circleName:hm.keySet()){
							Label cirName = new Label("You have in "+circleName +":");
							vp1.add(cirName);
							for(int id:hm.get(circleName).keySet()){
								Hyperlink commenterLink = new Hyperlink(hm.get(circleName).get(id), ""+id);
								vp1.add(commenterLink);
							}
							vp.add(vp1);
							
						}
						
					}
			});
			
		}
		catch(Exception e){
			e.printStackTrace();
		}
		
		return vp;
	}
}
